#include <iostream>
#include <string>
#include <math.h>
int count=0;
using namespace std;
void SameNumber();
void UnSameNumber();
int SIGN(long A);
long CalculateSame(long X, long Y, int n);

int main()
{
    SameNumber();
    return 0;
}

int SIGN(long A)
{
    return A > 0 ? 1 : -1;
}

void SameNumber()
{
    cout<<"X=";
    long X = 0;
    cin>>X;
    cout<<"Y=";
    long Y = 0;
    cin>>Y;
    cout<<"n=";
    int n = 0;
    cin>>n;

    long sum = CalculateSame(X, Y, n);
    cout<<"X*Y="<<X<<"*"<<Y<<"="<<sum<<endl;
}

long CalculateSame(long X, long Y, int n)
{
    int sign = SIGN(X) * SIGN(Y);

    X = abs(X);
    Y = abs(Y);
    if (X == 0 || Y == 0)
        return 0;
    else if (n == 1)
        return sign * X * Y;
    else
    {
        long A = (long)(X / pow(10, n / 2));
        long B = (X % (long)pow(10, n / 2));
        long C = (long)(Y / pow(10, n / 2));
        long D = (Y % (long)pow(10, n / 2));

        long AC = CalculateSame(A, C, n / 2);
        long BD = CalculateSame(B, D, n / 2);
        long ABCD = CalculateSame((A - B), (D - C), n / 2) + AC + BD;

        cout<<"A="<<A<<" B="<<B<<" C="<<C<<" D="<<D<<endl;

        return (long)(sign * (AC * pow(10, n) + ABCD * pow(10, n / 2) + BD));
    }
}
